import { useEffect, useImperativeHandle, useState } from 'react';
import { Toast } from 'react-vant';
import '../../index.less';
export default (props) => {
  // const [count, setCount] = useState(9)

  //定时器可以进行两个操作，一个是设置定时器的值为9，一个是设置为-1
  //9的情况是正常的下一回合
  //-1的情况是 我的回合，我刚放技能，技能还没有结束，技能结束之后需要手动再进行下一回合
  let timer: NodeJS.Timeout | null = null;
  useEffect(() => {
    timer && clearInterval(timer);
    return () => {
      clearInterval(timer);
    };
  }, []);

  useEffect(() => {
    if (props.count == -1) return clearInterval(timer);
    timer = setInterval(() => {
      props.setCount(props.count - 1);
      if (props.count == 1) {
        props.changeCurRound();
      }
    }, 1000);
    return () => {
      clearInterval(timer);
    };
  }, [props.count]);
  return (
    <>
      <span className="countdown">{props.count !== -1 && props.count}</span>
    </>
  );
};
